﻿using AutoMapper;
using MediatR;
using System.Collections.Generic;
using System.Threading.Tasks;
using EWC.HIS.Domain.Entities;
using System.Threading;
using EWC.Core.DependencyInjection;
using EWC.HIS.Domain.Repositories;
using System;
using EWC.HIS.Application.Contracts.AppointmentRegistrationService.Queries;

namespace EWC.HIS.Application.AppointmentRegistrations.Handlers
{
    public class GetAppointmentRegistrationsQueryHandler : IRequestHandler<GetAppointmentRegistrationsQuery, Tuple<int, IEnumerable<AppointmentRegistration>>>, IScopedDependency
    {

        private readonly IMapper _mapper;
        private readonly IAppointmentRegistrationRepository _appointmentRegistrationRepository;

        public GetAppointmentRegistrationsQueryHandler(IMapper mapper, IAppointmentRegistrationRepository appointmentRegistrationRepository)
        {
            _mapper = mapper;
            _appointmentRegistrationRepository = appointmentRegistrationRepository;
        }

        public async Task<Tuple<int, IEnumerable<AppointmentRegistration>>> Handle(GetAppointmentRegistrationsQuery request, CancellationToken cancellationToken)
        {
            IList<string> p_sqls = new List<string>();
            var registrations = await _appointmentRegistrationRepository.GetPagedAppointmentRegistrations("", "", request.PagingOptions.PageIndex, request.PagingOptions.PageSize);

            return _mapper.Map<Tuple<int, IEnumerable<AppointmentRegistration>>>(registrations);
        }
    }
}
